InboxType
Inbox
Inbox<'value> is one-way, drop-visible mail into an Elmish program: one queue, one reader, owned by a scope. Use it
for values that arrive from outside update — a host callback, another library's event, a search box whose input must
never block the UI thread. For work distribution or back-pressure between fibers, use
Queue directly.
Create inboxes
Build the inbox in the scope that shuts it down. A layer given to ElmishRuntime.startLayer is provisioned in the
runtime's root scope, so an inbox built there stays open for the program and is shut down with the runtime. The
environment field is filled with let! commands = Inbox.scopedSliding 1 inside the layer's flow { }, and nothing has to
register the inbox with the runtime afterwards.
scopedWith takes the QueueStrategy itself. The named constructors are the
four strategies:
scopedSliding capacitykeeps the newest pending value and evicts the oldest, so a burst collapses to the latest request.scopedDropping capacitykeeps the oldest pending value and refuses a newer offer.scopedBounded capacitywaits while the mailbox is full, so every value is delivered. Do not offer to it from aCmd: a command runs on the dispatch thread and would wait there. Offer from a fiber instead.scopedUnbounded()never waits and grows with the backlog.
create capacity runtime remains for a host that already holds the runtime. It drops
the newest offer (QueueStrategy.Dropping) and shuts the inbox down when the runtime stops.
Offer values
offer value inboxis an Elmish command:updatereturns it and the offer reaches the mailbox in dispatch order.post value inboxoffers immediately and reports whether the mailbox accepted the value, for a synchronous callback that cannot return a command.
Read the mailbox
stream inbox is the inbox as a FlowStream: every accepted value, in the order it
was offered. Read it once, because two readers split the mail between them. Pipe it through FlowStream.debounce and
FlowStream.switchMapFlow for search-as-you-type, then run it with Sub.OfFlowStream.subscribe.
dropped inbox counts the offers a full mailbox could not keep. Surface it next to
the search status so a coalesced search is visible instead of silent.
Specification
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Create inboxes | ||
| scopedWith | Inbox.scopedWith strategy | An inbox whose queue is shut down when the current scope closes, with the given strategy. |
| scopedSliding | Inbox.scopedSliding capacity | A non-blocking inbox in which the newest pending value survives a burst; the oldest is dropped. |
| scopedDropping | Inbox.scopedDropping capacity | A non-blocking inbox in which the oldest pending value survives; a newer offer is dropped. |
| scopedBounded | Inbox.scopedBounded capacity | A lossless inbox in which an offer waits while the mailbox is full. |
| scopedUnbounded | Inbox.scopedUnbounded () | A lossless inbox that never waits; memory grows with the backlog. |
| create | Inbox.create capacity runtime | An inbox shut down by the runtime instead of a scope, for a host that already holds the runtime. |
| Offer values | ||
| post | Inbox.post value inbox | Offers a value; returns whether the mailbox took it, false when it is full or shut down. |
| offer | Inbox.offer value inbox | The same offer, as a command for update to return. |
| Read the mailbox | ||
| stream | Inbox.stream inbox | The mailbox as a stream: every accepted value, in the order it was offered. |
| dropped | Inbox.dropped inbox | Offers that were made when the mailbox was full and could not be kept. |
| Dropped | this.Dropped | Offers made when the mailbox was full and could not wait. |
Create inboxes
Build the mailbox in the scope that will shut it down, naming its overflow strategy.
Offer values
Hand values to the program from update or from a synchronous callback.
Read the mailbox
Read values as a stream and count the offers a full mailbox could not keep.

